/**
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package ro.uvt.sp.lp.hw1.beermugs.algorithms;

import java.util.ArrayList;
import java.util.List;

/**
 * 
 * @author LP
 *
 */
public class State implements Cloneable {
	private int x;
	private int y;
	private State parent;
	
	/**
	 * 
	 */
	public State() {

	}

	/**
	 * 
	 * @param x
	 * @param y
	 * @param parent
	 */
	public State(int x, int y, State parent) {
		this.x = x;
		this.y = y;
		this.parent = parent;
	}

	/**
	 * 
	 * @return
	 */
	public int getX() {
		return x;
	}
	
	/**
	 * 
	 * @param x
	 */
	public void setX(int x) {
		this.x = x;
	}
	
	/**
	 * 
	 * @return
	 */
	public int getY() {
		return y;
	}
	
	/**
	 * 
	 * @param y
	 */
	public void setY(int y) {
		this.y = y;
	}
	
	/**
	 * 
	 * @return
	 */
	public State getParent() {
		return parent;
	}
	
	/**
	 * 
	 * @param parent
	 */
	public void setParent(State parent) {
		this.parent = parent;
	}
	
	/**
	 * 
	 */
	public boolean equals(Object state) { 
		return (((State) state).getX() == x && ((State) state).getY() == y);
	}
	
	/**
	 * construieste solutia de la root node la ultimul nod care compune solutia
	 * 
	 * @param children
	 * @return
	 */
	private List<State> getPath(List<State> children) {
		children.add(0, this);
		if (parent != null)
			children = parent.getPath(children);
		return (children);
	}
	
	/**
	 * 
	 * @return
	 */
	public List<State> getPath() {
		return (getPath(new ArrayList<State>()));
	}
	
	/**
	 * 
	 */
	public String toStringClassic() {
		return ("("+x + "," + y+")");
	}
	
	public String toString(){
		String xlvl1, xlvl2, xlvl3, xlvl4, ylvl1, ylvl2, ylvl3, ylvl4;
		xlvl1 = "       ";
		xlvl2 = "|   |  ";
		xlvl3 = "|   |  ";
		xlvl4 = "|   |  ";
		ylvl1 = "|   |\n";
		ylvl2 = "|   |\n";
		ylvl3 = "|   |\n";
		ylvl4 = "|   |\n";
		String lvlbot = "+---+  +---+\n" + "  X      Y  \n";

		switch (getX()) {
		case (0):
			break;
		case (1):
			xlvl4 = "|***|  ";
			break;
		case (2):
			xlvl4 = "|***|  ";
			xlvl3 = "|***|  ";
			break;
		case (3):
			xlvl4 = "|***|  ";
			xlvl3 = "|***|  ";
			xlvl2 = "|***|  ";
			break;
		default:
			break;
		}

		switch (getY()) {
		case (0):
			break;
		case (1):
			ylvl4 = "|***|\n";
			break;
		case (2):
			ylvl4 = "|***|\n";
			ylvl3 = "|***|\n";
			break;
		case (3):
			ylvl4 = "|***|\n";
			ylvl3 = "|***|\n";
			ylvl2 = "|***|\n";
			break;
		case (4):
			ylvl4 = "|***|\n";
			ylvl3 = "|***|\n";
			ylvl2 = "|***|\n";
			ylvl1 = "|***|\n";
			break;
		default:
			break;
		}
		String theString = xlvl1 + ylvl1 + xlvl2 + ylvl2 + xlvl3 + ylvl3
				+ xlvl4 + ylvl4 + lvlbot + "\n\n";
		return theString;
	}

}
